use std::convert::From;

#[derive(Debug)]
struct Number {
    value: i32,
}

impl From<i32> for Number {
    fn from(item: i32) -> Self {
        Number{value:item}
    }
}

fn from_test() {
    let num = Number::from(32);
    println!("My number is {:?}", num);
}

// use std::convert::Into;

// // here compiler report the following error:
// // conflicting implementations of trait `Into<Number>` for type `i32`
// // i'm not sure if this is relevant to compiler version, my rustc version is: rustc 1.69.0
// impl Into<Number> for i32 {
//     fn into(self) -> Number {
//         Number { value: self }
//     }
// }

// it seems the implementation of From and Into cannot be in the same rust unit
// we comment the upper code out, we can pass the compilation now

fn into_test() {
    let int = 5;
    let num: Number = int.into();
    println!("My number is {:?}", num);
}

fn main() {
    from_test();
    into_test();
}